package com.cloudlead.plugin.scheduler.action;

import com.cloudlead.common.lang.annotation.Label;
import com.cloudlead.common.lang.persistence.Filter;
import com.cloudlead.common.lang.persistence.Page;
import com.cloudlead.common.lang.persistence.PageRequest;
import com.cloudlead.common.lang.persistence.Sort;
import com.cloudlead.common.worker.action.impl.AbstractCrudActionFactory;
import com.cloudlead.common.worker.annotation.Action;
import com.cloudlead.common.worker.annotation.Order;
import com.cloudlead.common.worker.annotation.ValidatorGroup;
import com.cloudlead.common.worker.security.annotation.RequireGroups;
import com.cloudlead.plugin.scheduler.BusinessModules;
import com.cloudlead.plugin.scheduler.action.validator.ScheduleJobValidatorGroup;
import com.cloudlead.plugin.scheduler.service.ScheduleJobService;
import com.cloudlead.plugin.scheduler.vo.ScheduleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * ScheduleJobActionFactory is a Codegen action factory type
 */
@Label("计划任务管理")
@Controller("scheduleJobActionFactory")
@RequireGroups("administrator")
public class ScheduleJobActionFactory extends
        AbstractCrudActionFactory<ScheduleJobService, ScheduleJob> {

    @Autowired
    public ScheduleJobActionFactory(ScheduleJobService service) {
        super(BusinessModules.ScheduleJob, service);
    }

    @Action
    @Order(1)
    @ValidatorGroup(ScheduleJobValidatorGroup.Create.class)
    @Label("创建")
    @Override
    public ScheduleJob create(@NotNull ScheduleJob vo) {
        return super.create(vo);
    }

    @Action
    @Order(2)
    @Label("启动")
    public void start(@NotNull @Label("编号") String id) {
        service.updateScheduleJobStart(id);
    }

    @Action
    @Order(3)
    @Label("停止")
    public void stop(@NotNull @Label("编号") String id) {
        service.updateScheduleJobStop(id);
    }

    @Action
    @Order(4)
    @Label("暂停")
    public void pause(@NotNull @Label("编号") String id) {
        service.updateScheduleJobPause(id);
    }

    @Action
    @Order(5)
    @Label("恢复")
    public void resume(@NotNull @Label("编号") String id) {
        service.updateScheduleJobResume(id);
    }

    @Action
    @Order(6)
    @Label("查看")
    @Override
    public ScheduleJob view(@NotNull @Label("编号") String id) {
        return super.view(id);
    }

    @Action
    @Order(7)
    @Label("单值查询")
    @Override
    public ScheduleJob findOne(@NotNull Filter filter) {
        return super.findOne(filter);
    }

    @Action
    @Order(8)
    @Label("根据实例单值查询")
    @Override
    public ScheduleJob findOneByExample(
            @NotNull @Label("实例") ScheduleJob example) {
        return super.findOneByExample(example);
    }

    @Action
    @Order(9)
    @Label("统计")
    @Override
    public long count(Filter filter) {
        return super.count(filter);
    }

    @Action
    @Order(10)
    @Label("根据实例统计")
    @Override
    public long countByExample(@NotNull @Label("实例") ScheduleJob example) {
        return super.countByExample(example);
    }

    @Action
    @Order(11)
    @Label("列表查询")
    @Override
    public List<ScheduleJob> list(Filter filter, Sort sort) {
        return super.list(filter, sort);
    }

    @Action
    @Order(12)
    @Label("根据实例列表查询")
    @Override
    public List<ScheduleJob> listByExample(
            @NotNull @Label("实例") ScheduleJob example) {
        return super.listByExample(example);
    }

    @Action
    @Order(13)
    @Label("分页查询")
    @Override
    public Page<ScheduleJob> findAll(@NotNull PageRequest pageable) {
        return super.findAll(pageable);
    }

    @Action
    @Order(14)
    @Label("删除")
    @Override
    public ScheduleJob delete(@NotNull @Label("编号") String id) {
        return super.delete(id);
    }

}
